layui.use(['jquery', 'common', 'table', 'form'], function() {
	var $ = layui.jquery;
	var common = layui.common;
	var table = layui.table;
	var form = layui.form;

	table.render({
		elem: '#table',
		url: 'tableData',
		page: true,
		skin: 'line',
		request: {
			pageName: 'current',
			limitName: 'size'
		},
		cols: [[
			{field: 'image', title: '图片', templet: common.tableImageTemplet('image', 80, 'name')},
			{field: 'name', title: '名称'},
			{field: 'jName', title: '日文名称'},
			{field: 'eName', title: '英文名称'},
			{field: 'type', title: '类型'},
			{field: 'rare', title: '稀有度'},
			{field: 'description', title: '描述', minWidth: 480, templet: '<div><pre>{{d.description}}</pre></div>'}
		]],
		autoSort: false,
		initSort: {
			field: 'sort',
			type: 'asc'
		},
		where: {
			orderByField: 'sort',
			isAsc: true
		},
		done: function(res, curr, count) {
			common.tableImagePhotos(); 
		}
	});
	table.on('sort', function(obj) {
		table.reload('table', {
			initSort: obj,
			where: {
				orderByField: obj.field,
				isAsc: obj.type ? obj.type == 'asc' : null
			}
		})
	});
	form.on('submit(search)', function(data) {
		table.reload('table', {
			where: data.field,
			page: {
				curr: 1
			}
		});
	});
});